﻿using System.Collections;
using System.Collections.Generic;
using UnityEngine;


public class Food : MonoBehaviour {

	public const int FOOD_TYPE_NUM = 6;

	public enum FoodType{
		INVINCIBLE,  // 无敌
		LIFE,        // 加命
		LEVEL,       // 升级
		IRON,        // 铁墙
		BOMB,        // 炸弹
		HALT         // 停止
	};

	public Point Pos;            // 左上角位置
	private FoodType _type;
	public FoodType Type{
		get{ 
			return _type;
		}
		set{ 
			_type = value;
			Timer = Config.foodConfig.Duration[(int)_type];
		}
	}

	void Awake() {
		GameController controller = GameController.GetInstance ();
	}

	void Start () {
		_flickerTimer = 0;
		_i = 0;
	}
		
	private int _flickerTimer; // 用于控制物体闪烁
	public float Timer;        // 食物存在时间 
	private int _i;            // 用于逐渐加快闪烁速度
	void Update () {
		if (Timer > 0) {
			Timer -= Time.deltaTime;
			_flickerTimer++;

			if (_flickerTimer % ( Config.foodConfig.FlickerTimer - _i) == 0) {
				_flickerTimer = 0;
				Utils.ChangeHide (gameObject);
				if(_i < Config.foodConfig.FlickerTimer-5) _i++;
			}

			if (Timer <= 0) {
				GameController controller = GameController.GetInstance ();
				controller.Clear (gameObject);
			}
		}
	}
}
